package com.magold.logic.polygon;

import org.andengine.entity.modifier.AlphaModifier;
import org.andengine.extension.physics.box2d.PhysicsFactory;

import com.badlogic.gdx.physics.box2d.Body;
import com.badlogic.gdx.physics.box2d.BodyDef.BodyType;
import com.badlogic.gdx.physics.box2d.Contact;
import com.badlogic.gdx.physics.box2d.FixtureDef;
import com.magold.context.IContext;
import com.magold.context.IFixedEngine;
import com.magold.logic.ISpriteLogic;
import com.magold.logic.item.DisappearListener;
import com.magold.logic.magold.Magold;


public class WoodPrimitive extends PrimitiveLogic {
	private static Constants sConstants;
	private static FixtureDef sFixtureDef = PhysicsFactory.createFixtureDef(5.0f, 0.2f, 0.3f);
	public static void customize(Constants pConstants) {
		sConstants = pConstants;
	}
	
	public WoodPrimitive(PrimitiveShape pShape, BodyType pType) {
		super(pShape, sConstants.mRegion, pType);
	}

	/**
	 *  if be crushed by invincible magold, I will break.
	 */
	@Override
	public void startCollide(ISpriteLogic pAnother, Contact pContact) {
		if (pAnother instanceof Magold) {
			Magold player = (Magold) pAnother;
			if (player.isUsingSprintSkill()) {
				mShape.mConnector.setPhysicsEnabled(false);
				Body toDestroy = mShape.mConnector.getBody();
				toDestroy.getWorld().destroyBody(toDestroy);
				
				IFixedEngine engine = sConstants.mContext.getEngine();
				mShape.registerEntityModifier(new AlphaModifier(1, 1, 0, new DisappearListener(engine)));
			}
		}
	}

	@Override
	protected IContext getContext() {
		return sConstants.mContext;
	}

	@Override
	protected FixtureDef getFixtureDef() {
		return sFixtureDef;
	}

}
